package org.jeecg.modules.until;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

public class Sm4Util {
    //
    public static String key = "aaaabbbbccccdddd";

    /***
     * SM4加密
     * @param content
     * @return
     */
    public static String SM4encrypt(String content) {
        if(content==null||content.equals("")){
            return "";
        }
        SymmetricCrypto sm4 = SmUtil.sm4(key.getBytes());
        return sm4.encryptHex(content);
    }

    /***
     *SM4解密
     * @param encryptHex
     * @return
     */
    public static String SM4decrypt(String encryptHex) {
        if(encryptHex==null||encryptHex.equals("")){
            return "";
        }
        SymmetricCrypto sm4 = SmUtil.sm4(key.getBytes());
        return sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
    }
}
